<template>
    <div class="SHZY-common-layout">
        <div class="SHZY-common-layout-center">
            <el-row class="SHZY-common-search-box" :gutter="16">
                <el-form @submit.native.prevent="">
                    <el-col :span="6">
                        <el-form-item label="检验批号">
                            <el-input v-model="query.code" placeholder="检验批号" @keyup.enter.native="search" clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="物料">
                            <el-input v-model="query.material" placeholder="物料" @keyup.enter.native="search" clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="供应商">
                            <el-input v-model="query.supplier" placeholder="供应商" @keyup.enter.native="search" clearable />
                        </el-form-item>
                    </el-col>
                    <template v-if="showAll">
                        <el-col :span="6">
                            <el-form-item label="批次号">
                                <el-input v-model="query.batchNumber" placeholder="批次号" @keyup.enter.native="search"
                                    clearable />
                            </el-form-item>
                        </el-col>
                    </template>
                    <el-col :span="6">
                        <el-form-item>
                            <el-button type="primary" icon="el-icon-search" @click="search()">查询</el-button>
                            <el-button icon="el-icon-refresh-right" @click="reset()">重置</el-button>
                            <el-button type="text" icon="el-icon-arrow-down" @click="showAll = true"
                                v-if="!showAll">展开</el-button>
                            <el-button type="text" icon="el-icon-arrow-up" @click="showAll = false" v-else>收起</el-button>
                        </el-form-item>
                    </el-col>
                </el-form>
            </el-row>
            <div class="SHZY-common-layout-main SHZY-flex-main">
                <div class="SHZY-common-head">
                    <div>
                    </div>
                    <div class="SHZY-common-head-right">
                        <el-tooltip effect="dark" content="刷新" placement="top">
                            <el-link icon="icon-ym icon-ym-Refresh SHZY-common-head-icon" :underline="false"
                                @click="reset()" />
                        </el-tooltip>
                    </div>
                </div>
                <SHZY-table v-loading="listLoading" :data="list" custom-column>
                    <el-table-column prop="overdue" label="标记" width="70" align="center">
                        <template slot="header" slot-scope="scope">
                            <el-dropdown>
                                <span class="el-dropdown-link">标记 <i class="el-icon-question"></i>
                                </span>
                                <el-dropdown-menu slot="dropdown">
                                    <el-dropdown-item command="right"><i class="ym-custom ym-custom-checkbox-blank-circle"
                                            style="color:#ff625c;font-size:14px;">逾期 </i></el-dropdown-item>
                                    <el-dropdown-item command="bottom"><i class="ym-custom ym-custom-checkbox-blank-circle"
                                            style="color:#f9a646;font-size:14px;">即将逾期 </i></el-dropdown-item>
                                    <el-dropdown-item command="refresh"><i class="ym-custom ym-custom-checkbox-blank-circle"
                                            style="color:#6dcc51;font-size:14px;">正常</i></el-dropdown-item>
                                </el-dropdown-menu>
                            </el-dropdown>
                        </template>
                        <template slot-scope="scope">
                            <i class="ym-custom ym-custom-checkbox-blank-circle" style="color:#ff625c;font-size:16px;"
                                v-if="scope.row.overdue == 2"></i>
                            <i class="ym-custom ym-custom-checkbox-blank-circle" style="color:#f9a646;font-size:16px;"
                                v-else-if="scope.row.overdue == 1"></i>
                            <i class="ym-custom ym-custom-checkbox-blank-circle" style="color:#6dcc51;font-size:16px;"
                                v-else></i>
                        </template>
                    </el-table-column>
                    <el-table-column label="检验批号" prop="code" width="150" align="left">
                    </el-table-column>
                    <el-table-column label="检验日期" prop="date" width="150" align="left" :formatter="shzy.tableDateFormat">
                    </el-table-column>
                    <el-table-column label="报检类型" prop="type" width="100" align="left">
                    </el-table-column>
                    <el-table-column label="物料名称" prop="materialDes" min-width="150" :show-overflow-tooltip="true"
                        align="left">
                        <template slot-scope="scope">
                            {{ scope.row.materialDes }}
                        </template>
                    </el-table-column>
                    <el-table-column label="物料编码" prop="materialCode" min-width="150" :show-overflow-tooltip="true"
                        align="left">
                        <template slot-scope="scope">
                            {{ scope.row.materialCode }}
                        </template>
                    </el-table-column>
                    <el-table-column label="供应商" prop="supplier" min-width="150" :show-overflow-tooltip="true" align="left">
                        <template slot-scope="scope">
                            {{ scope.row.supplier + " " + scope.row.supplierDes }}
                        </template>
                    </el-table-column>
                    <el-table-column label="采购订单号" prop="orderNo" width="150" align="left">
                    </el-table-column>
                    <el-table-column label="来料数量" prop="incomingQty" width="100" align="left">
                    </el-table-column>
                    <el-table-column label="批次号" prop="batchNumber" width="150" align="left">
                    </el-table-column>
                    <el-table-column label="检验员" prop="employeeName" width="100" align="left">
                    </el-table-column>
                    <el-table-column label="检验类型" prop="inspectType" width="100" align="left">
                        <template slot-scope="scope">
                            {{ getInspectTypeDes(scope.row.inspectType) }}
                        </template>
                    </el-table-column>
                    <el-table-column label="状态" prop="status" width="100" align="left">
                        <template slot-scope="scope">
                            <el-tag v-if="scope.row.status == 0" type="info">未检验</el-tag>
                            <el-tag v-if="scope.row.status == 1">检验中</el-tag>
                            <el-tag v-if="scope.row.status == 2" type="success">已检验</el-tag>
                            <el-tag v-if="scope.row.status == 3" type="warning">已过帐</el-tag>
                        </template>
                    </el-table-column>
                    <el-table-column label="操作" fixed="right" width="100">
                        <template slot-scope="scope">
                            <el-button type="text" @click="addOrUpdateHandle(scope.row.id)">检验</el-button>
                            <!-- <el-button type="text" @click="handlePrint(scope.row.code)">打印</el-button> -->
                            <!-- <el-button type="text" @click="handleDel(scope.row.id)" class='SHZY-table-delBtn'>删除</el-button> -->
                        </template>
                    </el-table-column>
                </SHZY-table>
                <pagination :total="total" :page.sync="listQuery.currentPage" :limit.sync="listQuery.pageSize"
                    @pagination="initData" />
            </div>
        </div>
        <SHZY-Form v-if="formVisible" ref="SHZYForm" @refresh="refresh" />
        <!-- <print-browse :visible.sync="printBrowseVisible" id="455151438088129413" :formId="formId" :fullName="fullName" /> -->
    </div>
</template>
<script>
import PrintBrowse from '@/components/PrintBrowse'
import { getInspectionlotList } from '@/api/q1/business/inspectionLot'
import SHZYForm from './Form'
export default {
    components: { SHZYForm, PrintBrowse },
    name: "business-inspectionWait",
    data() {
        return {
            showAll: false,
            query: {
                code: undefined,
                date: undefined,
                type: undefined,
                material: undefined,
                supplier: undefined,
                batchNumber: undefined,
            },
            list: [],
            listLoading: true,
            multipleSelection: [],
            total: 0,
            listQuery: {
                currentPage: 1,
                pageSize: 20,
                sort: "desc",
                sidx: "",
            },
            formVisible: false,
            printBrowseVisible: false,
            formId: "",
            fullName: "",
            batchTypeList: []
        }
    },
    computed: {
        menuId() {
            return this.$route.meta.modelId || ''
        }
    },
    created() {
        this.getDictionaryData()
        this.initData()
    },
    methods: {
        getDictionaryData() {
            this.$store.dispatch('base/getDictionaryData', { sort: 'BatchType' }).then((res) => {
                this.batchTypeList = res
            })
        },
        getInspectTypeDes(enCode) {
            let batchTypeInfo = this.batchTypeList.find(x => x.enCode == enCode)
            if (batchTypeInfo) {
                return batchTypeInfo.fullName
            } else {
                return ""
            }
        },
        initData() {
            this.listLoading = true;
            let _query = {
                ...this.listQuery,
                ...this.query,
                menuId: this.menuId,
            };
            let query = {}
            for (let key in _query) {
                if (Array.isArray(_query[key])) {
                    query[key] = _query[key].join()
                } else {
                    query[key] = _query[key]
                }
            }
            query.statusType = "Wait"
            getInspectionlotList(query).then(res => {
                this.list = res.data.list
                this.total = res.data.pagination.total
                this.listLoading = false
            })
        },
        addOrUpdateHandle(id) {
            this.formVisible = true
            this.$nextTick(() => {
                this.$refs.SHZYForm.init(id)
            })
        },
        search() {
            this.listQuery = {
                currentPage: 1,
                pageSize: 20,
                sort: "desc",
                sidx: "",
            }
            this.initData()
        },
        refresh(isrRefresh) {
            this.formVisible = false
            if (isrRefresh) this.reset()
        },
        reset() {
            for (let key in this.query) {
                this.query[key] = undefined
            }
            this.listQuery = {
                currentPage: 1,
                pageSize: 20,
                sort: "desc",
                sidx: "",
            }
            this.initData()
        },
        handlePrint(code) {
            this.fullName = "报告单"
            this.formId = code
            this.printBrowseVisible = true
        }
    }
}
</script>